package com.wanger.swc.config.dataInstance.model;

import com.wanger.swc.exception.BusEx;
import com.wanger.swc.util.validation.MyVerifyUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @Author: wanger
 * @Date: 2025/3/11 10:49
 * @Description: 定义支持的类型，并用于实现类做标记
 */
@Getter
@AllArgsConstructor
public enum DataInstanceType {
    JSON("json", "json格式"),
    YAML("yaml", "yml/yaml格式"),
    PROPERTY("property", "property格式"),
    XML("xml", "xml格式");

    private final String type;
    private final String desc;

    /**
     * 选举枚举
     *
     * @param type 给的类型
     * @return 目标枚举
     */
    public static DataInstanceType getByType(String type) {
        MyVerifyUtil.nullVerify(type, "类型不能为空！");
        for (DataInstanceType value : values()) {
            if (value.getType().equals(type)) {
                return value;
            }
        }
        throw BusEx.create("类型未找到！");
    }

}
